﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static ArrayList list = new ArrayList();
        
        static Student student1 = new Student(1, "张三", 18);
       static Student student2 = new Student(2, "李四", 20);
       static  Student student3 = new Student(3, "王五", 19);
    
        static Hashtable ht = new Hashtable();
        static void Main(string[] args)
        {
            ht.Add(student1.num, student1);
            ht.Add(student2.num, student2);
            ht.Add(student3.num, student3);
            list.Add( student1);
            list.Add( student2);
            list.Add( student3);
            stuinfo();


            Console.WriteLine("------------------------");
            

        }
        public static void stuinfo()
        {
            Console.WriteLine("1、添加学生信息。2、查询学生信息。");
            int key = int.Parse(Console.ReadLine());
            switch (key)
            {
                case 1:
                    Console.WriteLine("请输入学号");
                    int num = int.Parse(Console.ReadLine());
                    
                    
                    Console.WriteLine("请输入姓名");
                    string name = Console.ReadLine();
                    Console.WriteLine("请输入年龄");
                    int age = int.Parse(Console.ReadLine());
                    
                    Student student = new Student(num,name,age);
                    
                    if (ht.Contains(student.num))
                    {
                        Console.WriteLine("错误");
                        
                    }
                    else
                    {
                        ht.Add(student.num, student);
                        list.Add(student);
                       
                    }
                    
                    stuinfo();
                    break;
                case 2:

                    chaxu();

                    break;
                default:
                    break;
            }
            
        }
        static void chaxu()
        {
            Console.WriteLine("1、查询所有（按学号排序）2、查询所有（按姓名排序），3、查询所有（按年龄排序）4、按学号查询（查没有，则打印查无此学生）5、退出");
           int key = int.Parse(Console.ReadLine());
            switch (key)
            {
                case 1:
                    
                    list.Sort(new NumSort());
                    foreach (var item in list)
                    {
                        Console.WriteLine(item);
                    }
                    break;
                case 2:
                    list.Sort(new namesort());
                    foreach (var item in list)
                    {
                        Console.WriteLine(item);
                    }
                    break;
                case 3:
                    list.Sort(new agesort());
                    foreach (var item in list)
                    {
                        Console.WriteLine(item);
                    }
                    break;
                case 4:
                    Console.WriteLine("请输入你要查的学号");
                    int a = int.Parse(Console.ReadLine());
                    if (ht.Contains(a))
                    {
                        Console.WriteLine(ht[a]);
                    }
                    else
                    {
                        Console.WriteLine("查无此学生");
                    }
                    break;
                case 5:
                    stuinfo();
                    break;
                default:
                    break;
            }
        }
    }
}
